package cn.virens.common.boot.mybatis.autoconfig;

import cn.virens.common.mybatis.datasource.DynamicDataSource;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Role;

/**
 * 数据库配置
 *
 * @文件 :DataSourceConfig.java
 * @作者 :cn.loioi
 * @创建时间 :2016年10月13日 下午1:11:48
 */
@AutoConfiguration
@Role(value = BeanDefinition.ROLE_INFRASTRUCTURE)
@EnableConfigurationProperties({DynamicDataSourceProperties.class})
@ConditionalOnProperty(prefix = "spring.datasource.virens", value = "enabled")
public class DynamicDataSourceAutoConfig {

    @Bean(value = "dynamicDataSource")
    @ConditionalOnMissingBean(name = "dynamicDataSource")
    public DynamicDataSource dynamicDataSource(DynamicDataSourceProperties properties) {
        return new DynamicDataSourceWarp(properties);
    }
}
